<script setup>
import {onMounted, ref} from 'vue';
import {baseStore} from "@/store/baseStore.js";

const collapsed = ref(false);
const selectedKeys = ref(['1']);
const selectedKeys1 = ref(['2']);

let bs = baseStore()
let {menuTab,token} = storeToRefs(bs)
const socket = inject('socket')
const bus = inject('bus')


const onResize = () =>{
    window.addEventListener('resize', (e) => {
        bus.emit('resize',e)
    });
}
onMounted(() => {
    onResize()
    socket.init(token.value)
    bus.on(socket.const_p[1],(evt) => {
        if(!evt.reason){
            return
        }
        bs.token = null
        location.reload()
    })
})
</script>

<template>
    <a-layout style="min-height: 100vh">
        <!-- 头部-->
        <a-layout-header theme="dark" style="background: #fff; padding:0">
            <div class="logo" />

            <menu-unfold-outlined
                v-if="collapsed"
                class="trigger"
                @click="() => (collapsed = !collapsed)"
            />
            <menu-fold-outlined v-else class="trigger" @click="() => (collapsed = !collapsed)" />

        </a-layout-header>
        <a-layout>
            <!-- 左侧 -->
            <a-layout-sider :trigger="null" v-model:collapsed="collapsed" collapsible>
                <a-menu v-model:selectedKeys="selectedKeys" theme="dark" mode="inline">
                    <a-menu-item key="1">
                        <pie-chart-outlined/>
                        <span>Option 1</span>
                    </a-menu-item>
                    <a-menu-item key="2">
                        <desktop-outlined/>
                        <span>Option 2</span>
                    </a-menu-item>
                    <a-sub-menu key="sub1">
                        <template #title>
            <span>
              <user-outlined/>
              <span>User</span>
            </span>
                        </template>
                        <a-menu-item key="3">Tom</a-menu-item>
                        <a-menu-item key="4">Bill</a-menu-item>
                        <a-menu-item key="5">Alex</a-menu-item>
                    </a-sub-menu>
                    <a-sub-menu key="sub2">
                        <template #title>
            <span>
              <team-outlined/>
              <span>Team</span>
            </span>
                        </template>
                        <a-menu-item key="6">Team 1</a-menu-item>
                        <a-menu-item key="8">Team 2</a-menu-item>
                    </a-sub-menu>
                    <a-menu-item key="9">
                        <file-outlined/>
                        <span>File</span>
                    </a-menu-item>
                </a-menu>
            </a-layout-sider>
            <!-- 内容-->
            <a-layout-content :style="{ margin: '10px', padding: '10px', background: '#fff', minHeight: '280px', }">
                <router-view v-slot="{ Component }">
                    <KeepAlive :include="menuTab">
                        <component :is="Component"/>
                    </KeepAlive>
                </router-view>
            </a-layout-content>
<!--            &lt;!&ndash; 脚&ndash;&gt;-->
<!--            <a-layout-footer style="text-align: center">-->
<!--                Ant Design ©2018 Created by Ant UED-->
<!--            </a-layout-footer>-->
        </a-layout>
    </a-layout>
</template>

<style scoped lang="scss">
.logo {
    float: left;
    width: 120px;
    height: 31px;
    margin: 16px 24px 16px 0;
    background: rgba(255, 255, 255, 0.3);


}
</style>